package lxm.demo.ultra;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;


public class UltraActivity extends AppCompatActivity {

    public static final String ULTRA_FRAGMENT_CLASS_NAME = "fragment_name";

    @BindView(R2.id.toolBar_ultra_detail)
    Toolbar toolBar;
    @BindView(R2.id.frame_detail)
    FrameLayout frameLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ultra);
        String clsName = getIntent().getStringExtra(ULTRA_FRAGMENT_CLASS_NAME);
        ButterKnife.bind(this);
        toolBar.setTitle(clsName);
        setSupportActionBar(toolBar);
        addFragment(clsName);
    }


    private void addFragment(String clsName) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = null;
        if (TextUtils.equals(PtrFrameFragment.class.getName(), clsName)) {
            fragment = PtrFrameFragment.getInstance();
        } else if (TextUtils.equals(WaveHeaderFragment.class.getName(), clsName)) {
            fragment = WaveHeaderFragment.getInstance();
        } else if (TextUtils.equals(StoreHouseHeaderFragment.class.getName(), clsName)) {
            fragment = StoreHouseHeaderFragment.getInstance();
        }
        fm.beginTransaction().add(R.id.frame_detail, fragment, clsName).show(fragment)
                .commit();
    }

}
